package com.bt.lms.ui.page.classes;
import com.bt.lms.ui.action.divide.plan.DivideBtnAction;
import com.bt.lms.ui.action.divide.plan.ViewClassAction;
import com.bt.lms.ui.action.divide.plan.ViewStuBtnAction;
import com.bt.lms.ui.vo.EnpPlanProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;

import java.util.ArrayList;
import java.util.List;

/**
 * 招生计划列表页面
 */
public class EnrollmentPlanList extends VBox {

    /**
     * 宽
     */
    private Integer preWidth = 1280;

    /**
     * 高
     */
    private Integer preHeight = 600;

    public EnrollmentPlanList(){
        this.setPrefSize(preWidth,preHeight);
        this.setSpacing(10);
        this.setPadding(new Insets(20));
        //横盒子
        HBox hBox = new HBox();
        hBox.setPrefHeight(preHeight*0.1);
        initHBox(hBox);
        this.getChildren().add(hBox); //横盒子放入VBox里
        //创建表格组件
        TableView table = new TableView();
        //创建列
        TableColumn planCodeCol = new TableColumn<>("招生计划编号");
        planCodeCol.setPrefWidth(120);
        TableColumn planNameCol = new TableColumn<>("招生计划名称");
        planNameCol.setPrefWidth(120);
        TableColumn enrollmentSchoolCol = new TableColumn<>("招生院校");
        enrollmentSchoolCol.setPrefWidth(120);
        TableColumn enrollmentLevelCol = new TableColumn<>("招生层次");
        enrollmentLevelCol.setPrefWidth(120);
        TableColumn enrollmentMajorCol = new TableColumn<>("招生专业");
        enrollmentMajorCol.setPrefWidth(120);
        TableColumn enrollmentNumberCol = new TableColumn<>("录取人数");
        enrollmentNumberCol.setPrefWidth(120);
        TableColumn shiftStatusCol = new TableColumn<>("分班状态");
        shiftStatusCol.setPrefWidth(120);
        TableColumn classNumberCol = new TableColumn<>("班级数量");
        classNumberCol.setPrefWidth(120);
        TableColumn handleCol = new TableColumn<>("操作");
        handleCol.setPrefWidth(200);
        //第一行按钮盒子
        HBox hBox1 = new HBox();
        Button divideBtn= new Button("分班");
        divideBtn.setCursor(Cursor.HAND); //添加鼠标移入出现小手图案
        divideBtn.setPrefWidth(100);
        Color rgb = Color.rgb(49,193,231);
        BackgroundFill backgroundFill = new BackgroundFill(rgb,null,null);
        Background background = new Background(backgroundFill);
        divideBtn.setBackground(background);
        //事件
        DivideBtnAction divideBtnAction = new DivideBtnAction();
        divideBtn.setOnAction(divideBtnAction);

        Button viewStuBtn = new Button("查看学员");
        viewStuBtn.setPrefWidth(100);
        viewStuBtn.setCursor(Cursor.HAND); //添加鼠标移入出现小手图案
        Color rgb1 = Color.rgb(49,193,231);
        BackgroundFill backgroundFill1 = new BackgroundFill(rgb1,null,null);
        Background background1 = new Background(backgroundFill1);
        viewStuBtn.setBackground(background1);
        //事件
        ViewStuBtnAction viewStuBtnAction = new ViewStuBtnAction();
        viewStuBtn.setOnAction(viewStuBtnAction);
        hBox1.getChildren().addAll(divideBtn,viewStuBtn);
        //第二行按钮盒子
        HBox hBox2 = new HBox();
        Button adjustClassBtn = new Button("查看/调整分班");
        adjustClassBtn.setCursor(Cursor.HAND); //添加鼠标移入出现小手图案
        hBox2.getChildren().add(adjustClassBtn);
        Color rgb2 = Color.rgb(49,193,231);
        BackgroundFill backgroundFill2 = new BackgroundFill(rgb2,null,null);
        Background background2 = new Background(backgroundFill2);
        adjustClassBtn.setBackground(background2);
        //事件
        ViewClassAction viewClassAction = new ViewClassAction();
        adjustClassBtn.setOnAction(viewClassAction);
        //分班状态盒子
        HBox hBox3 = new HBox();
        Label undividedShiftLab = new Label("未分班");
        Color rgb4 = Color.rgb(255,120,120);
        undividedShiftLab.setTextFill(rgb4);
        hBox3.getChildren().add(undividedShiftLab);
        HBox hBox4 = new HBox();
        Label dividedShiftLab = new Label("已分班");
        Color rgb5 = Color.rgb(120,185,0);
        dividedShiftLab.setTextFill(rgb5);
        hBox4.getChildren().add(dividedShiftLab);


        //把列放入表头
        table.getColumns().addAll(planCodeCol,planNameCol,enrollmentSchoolCol,enrollmentLevelCol,enrollmentMajorCol,enrollmentNumberCol,shiftStatusCol,classNumberCol,handleCol);

        //表格当中加数据[集合]
        EnpPlanProperty enpPlanProperty01 = new EnpPlanProperty("0001","网联培训计划","西南大学","免费师范生","数学与应用数学",500,hBox3, 0,hBox1);
        EnpPlanProperty enpPlanProperty02 = new EnpPlanProperty("0002","网联培训计划","西南大学","免费师范生","数学与应用数学",500,hBox4, 5,hBox2);
        List<EnpPlanProperty> enpPlanProperty = new ArrayList<>();
        enpPlanProperty.add(enpPlanProperty01);
        enpPlanProperty.add(enpPlanProperty02);
        //将用户数据集合转换成Javafx组件集合
        ObservableList<EnpPlanProperty> properties = FXCollections.observableArrayList(enpPlanProperty);
        //把数据放入表格当中
        table.setItems(properties);

        //配置列映射，让每一列知道要展示的属性是哪一个
        planCodeCol.setCellValueFactory(new PropertyValueFactory<EnpPlanProperty, String>("enpPlanNumber"));
        planNameCol.setCellValueFactory(new PropertyValueFactory<EnpPlanProperty, String>("planName"));
        enrollmentSchoolCol.setCellValueFactory(new PropertyValueFactory<EnpPlanProperty, String>("enrollmentSchool"));
        enrollmentLevelCol.setCellValueFactory(new PropertyValueFactory<EnpPlanProperty, String>("enpLevel"));
        enrollmentMajorCol.setCellValueFactory(new PropertyValueFactory<EnpPlanProperty, String>("enpMajor"));
        enrollmentNumberCol.setCellValueFactory(new PropertyValueFactory<EnpPlanProperty, Integer>("enpPopulation"));
        shiftStatusCol.setCellValueFactory(new PropertyValueFactory<EnpPlanProperty, String>("shiftStatus"));
        classNumberCol.setCellValueFactory(new PropertyValueFactory<EnpPlanProperty, Integer>("classNumber"));
        handleCol.setCellValueFactory(new PropertyValueFactory<EnpPlanProperty, HBox>("handle"));

        //表格放到面板当中
        this.getChildren().add(table);

        //分页查询
        HBox hBox6 = new HBox();
        hBox6.setSpacing(6);
        hBox6.setAlignment(Pos.CENTER_RIGHT);
        Label firstLab  = new Label("<<首页");
        //颜色
        Color rgb3 = Color.rgb(120,185,0);
        firstLab.setTextFill(rgb3);
        Label lastLab = new Label("<<上一页");
        lastLab.setTextFill(rgb3);
        Button oneLab = new Button("1");
        Button twoLab = new Button("2");
        Button threeLab = new Button("3");
        Button fourLab = new Button("4");
        Label nextLab = new Label("下一页>>");
        nextLab.setTextFill(rgb3);
        Label endLab = new Label("尾页>>");
        endLab.setTextFill(rgb3);
        Label allLab = new Label("总记录数100条");
        TextField pageTF = new TextField();
        pageTF.setPrefWidth(20);
        Label pageLab = new Label("/10");
        Button goBtn = new Button("GO");
        hBox6.getChildren().addAll(firstLab,lastLab,oneLab,twoLab,threeLab,fourLab,nextLab,endLab,allLab,pageTF,pageLab,goBtn);
        this.getChildren().add(hBox6);
    }

    private void initHBox(HBox hBox) {
        hBox.setSpacing(20);
        //下拉框
        ComboBox planCB = new ComboBox();
        planCB.setPromptText("按招生计划");
        planCB.getItems().add("按招生计划");
        planCB.getItems().add("按培训项目");
        planCB.getItems().add("按招生院校");
        planCB.getItems().add("按招生层次");
        planCB.getItems().add("按招生专业");
        planCB.setCursor(Cursor.HAND);  //添加鼠标移入出现小手图案
        hBox.getChildren().add(planCB);
        //模糊查询标签
        Label searchLab = new Label("模糊查询");
        hBox.getChildren().add(searchLab);
        //文本框
        TextField searchTF = new TextField();
        searchTF.setPromptText("输入招生计划名称");
        hBox.getChildren().add(searchTF);
        //分班状态标签
        Label shiftStatusLab = new Label("分班状态");
        hBox.getChildren().add(shiftStatusLab);
        //下拉框
        ComboBox statusCB = new ComboBox();
        statusCB.setPromptText("全部");
        statusCB.getItems().add("全部");
        statusCB.getItems().add("未分班");
        statusCB.getItems().add("已分班");
        statusCB.setCursor(Cursor.HAND); //添加鼠标移入出现小手图案
        hBox.getChildren().add(statusCB);
        //搜索按钮
        Button searchBtn = new Button("搜索");
        searchBtn.setCursor(Cursor.HAND); //添加鼠标移入出现小手图案
        hBox.getChildren().add(searchBtn);

    }
}
